package com.hk.commons.poi.excel.read.sax.v03;

import com.hk.commons.poi.excel.read.sax.ReadContext;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.poi.hssf.eventusermodel.EventWorkbookBuilder;
import org.apache.poi.hssf.eventusermodel.FormatTrackingHSSFListener;
import org.apache.poi.hssf.record.BoundSheetRecord;
import org.apache.poi.hssf.record.SSTRecord;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import java.util.*;


/**
 * @author Kevin
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class XlsReadContext extends ReadContext {

    /**
     * 当前是否为一个sheet
     */
    private boolean isSheet;

    private boolean parseAllSheet;

    /**
     * 开始读取的sheet位置
     */
    private int startSheetIndex = 0;

    /**
     * 上传表格需要读取的sheet最大的索引
     */
    private int maxSheetIndex = 0;

    /**
     * 要解析的标题行
     */
    private int titleRow;

    /**
     * 是否输出公式单元格的值
     */
    private boolean outputFormulaValue;

    private FormatTrackingHSSFListener formatListener;

    private boolean outputNextStringRecord;

    private short nextColumn;

    /**
     * 单元格的值
     */
    private Map<Number, String> columnValueMap = new HashMap<>();

    /**
     * 存储了在Excel中文本单元格中的文本值，文本单元格通过索引获取文本值
     */
    private SSTRecord sstRecord;

    private List<BoundSheetRecord> boundSheetRecords = new ArrayList<>();

    /**
     * 排序后的 sheet
     */
    private BoundSheetRecord[] orderBoundSheetRecords;

    private HSSFWorkbook stubWorkbook;

    /**
     * 解析公式
     */
    private EventWorkbookBuilder.SheetRecordCollectingListener workbookBuildingListener;

    /**
     * 当前sheet是否 不解析
     */
    public boolean ignoreSheet() {
        var currentSheetIndex = getCurrentSheetIndex();
        if (Objects.isNull(currentSheetIndex)) {
            return true;
        }
        return !isParseAllSheet() && (currentSheetIndex < getStartSheetIndex() || currentSheetIndex > getMaxSheetIndex());
    }

    public boolean isTitleRow(int row) {
        return this.titleRow == row;
    }

//    /**
//     * 批注的记录，这里暂时还没使用这个变量
//     */
//    private Integer tempObjectIndex;

    // 批注comment
//    private Map<Integer, String> objectCacheMap = new HashMap<>();


}
